package com.turnos.gestion.administracion;

import java.util.ArrayList;

import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zul.Textbox;

import com.coreweb.componente.BodyPopupAceptarCancelar;
import com.coreweb.componente.WindowPopup;
import com.coreweb.control.SimpleViewModel;
import com.coreweb.util.MyArray;

public class ImpresorasControlBody extends SimpleViewModel {
	
	
	private MyArray selectedItem = new MyArray();
	private ArrayList<MyArray> lista = new ArrayList<>();
	private ImpresorasAssembler ass = null;
	private ImpresoraDTO iDto = null;
	
	@Init(superclass = true)
	public void init() throws Exception {
		this.ass = new ImpresorasAssembler();
		this.iDto = ass.getImpresorasDTO();
		this.lista = this.iDto.getClienteImpresoras();
		System.out.println("======================"+this.lista.size());
	}

	
	@AfterCompose
	public void afterCompose() {
	}


	@Command
	@NotifyChange ("*")
	public void agregar() throws Exception{
		Textbox alias = new Textbox();
		Textbox ipMaquina = new Textbox();
		Textbox urlImpresora = new Textbox();
		
		BodyPopupAceptarCancelar bp = new BodyPopupAceptarCancelar();
		bp.setHighWindows("600px");
		bp.addComponente("Alias (ej. Laura)", alias);
		bp.addComponente("Login usuario (ej. turno)", ipMaquina);
		bp.addComponente("URL Impresora (ej. http://10.25.3.xxx:8090)", urlImpresora);
		
		bp.showPopup("Configurar Máquina-Impresora");
		if (bp.isClickAceptar()==true){
			String aliasStr = alias.getValue();
			String ipMaquinaStr = ipMaquina.getValue();
			String urlImpresoraStr = urlImpresora.getValue();
			MyArray ma = new MyArray();
			ma.setPos1(aliasStr);
			ma.setPos2(ipMaquinaStr);
			ma.setPos3(urlImpresoraStr);
			this.lista.add(ma);
			ass.dtoToDomain(this.iDto);
		}
		
	}
	
	@Command
	@NotifyChange ("*")
	public void eliminar() throws Exception{
		String txt = "Eliminar este registro?";
		if (this.mensajeSiNo(txt)== true){
			this.lista.remove(this.selectedItem);
			ass.dtoToDomain(this.iDto);
		}
		
	}
	
		
	public ArrayList<MyArray> getLista() {
		return lista;
	}


	public void setLista(ArrayList<MyArray> lista) {
		this.lista = lista;
	}


	public MyArray getSelectedItem() {
		return selectedItem;
	}


	public void setSelectedItem(MyArray selectedItem) {
		this.selectedItem = selectedItem;
	}
	
	
	
	
}
